/* 
 * File:   SCcreen.h
 * Author: cow
 *
 * Created on July 29, 2011, 2:28 AM
 */

#ifndef SCCREEN_H
#define	SCCREEN_H

//Includes---------------------------------------
#include <SDL/SDL.h>
#include <pthread.h>
#include <map>
#include <string>
#include <cairo/cairo.h>
#include "../cantrips/handlers.h"
#include "../cantrips/ImageFormats.h"
using namespace std;
//Includes=======================================

//Defines----------------------------------------
#define screenManIterator map<string, screen*>::iterator
//Defines========================================

//Prototypes-------------------------------------
class screen;
class screenManager;
//Prototypes=====================================

//definitions------------------------------------
class screen : public updateHandler, public eventHandler{
public:
	//construction------
	screen(int w = SDL_GetVideoSurface()->w, int h = SDL_GetVideoSurface()->h);
	~screen();
	//access------------
	bool getVisible();
	cairo_surface_t* getCairoSurface();
	screen* getChild(int c);
	int getWidth();
	int getHeight();
	//manipulations-----
	virtual void setBackground(Uint32 r, Uint32 g, Uint32 b);
	virtual void setBackground(image* bgImage);
	virtual void addImage(image* i, int xPos, int yPos);
	//screen parenting--
	void addChild(screen* s, int x, int y, int w, int h);
	void removeChild(screen* s);
	void removeChild(int i);
	//view manipulation-
	virtual void setWindowPosition(int x, int y, int w = SDL_GetVideoSurface()->w, int h = SDL_GetVideoSurface()->h);
	virtual void scrollDrawPosition(int x, int y);
	virtual void setDrawPosition(int x, int y);
	virtual void draw();
	virtual void draw(SDL_Surface* window);
	void setVisible(bool isVisible);
	//update handlers---
	virtual void onUpdate(float timeElapsed);
	virtual void addUpdateHandler(updateHandler* uh);
	virtual void removeUpdateHandler(updateHandler* uh);
	//event handlers----
	virtual bool onEvent(SDL_Event* e);
	virtual void addEventHandler(eventHandler* e);
	virtual void removeEventHandler(eventHandler* e);
	//activation routines
	virtual void onActivate(SDL_Surface* s);
	virtual void onDeactivate();
protected:
	//screen information
	SDL_Surface* window;
	SDL_Surface* drawSurface;
	SDL_Rect drawPosition;
	SDL_Rect windowPosition;
	SDL_Rect screenSize;
	//draw info---------
	bool visible;
	//background info---
	image* bgImg;
	Uint32 bgCol;
	//cairo information-
	cairo_surface_t* cairosurf;
	//handlers----------
	list<updateHandler*> updateHandlers;
	list<eventHandler*> eventHandlers;
	//children----------
	map<screen*, int*> children;
	//images------------
	list<image*> images;
};
class screenManager{
public:
	//constructor-------
	screenManager(SDL_Surface* window);
	screenManager();
	~screenManager();
	//access------------
	screen* getScreen(string screenName);
	screen* getActiveScreen();
	//manipulation------
	bool registerScreen(string screenName, screen* scr);;
	screen* unregisterScreen(string screenName);
	//activations-------
	bool activateScreen(screen* scr);
	bool activateScreen(string screenName);
	bool activateScreen(string screenName, int x, int y, int w, int h);
	bool deactivateScreen(string screenName);
	//iterators---------
	screenManIterator begining();
	screenManIterator end();
private:
	screen* activeScreen;
	SDL_Surface* parent;
	map<string, screen*> screenCatalog;
};
//===============================================
#endif	/* SCCREEN_H */